package com.g1.controller;

import com.g1.entity.Cook;
import com.g1.entity.Student;
import com.g1.service.CookService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/cook")
public class CookController {

    @Autowired
    private CookService cookService;


    @RequestMapping("selectAll")
    public String selectAll(HttpServletRequest request){

        List<Cook> cook = cookService.selectAll();
        request.setAttribute("cook",cook);
        return "cookList";
    }

    @RequestMapping("selectById")
    public String  selectById(@RequestParam("id") Long id,HttpServletRequest request){
        Cook cook = cookService.selectById(id);
        request.setAttribute("cook",cook);
        return "updateCook";
    }

    @RequestMapping("update")
    public String update(Cook cook){
        int update = cookService.update(cook);
        return "redirect:/cook/selectAll";
    };



    @RequestMapping("delete")
    public String delete(@RequestParam("id") Long id){
        int update = cookService.delete(id);
        return "redirect:/cook/selectAll";
    };


    @RequestMapping("add")
    public String add(Cook cook){
        int update = cookService.insert(cook);
        return "redirect:/cook/selectAll";
    };
}
